﻿ 
using System;
using System.Collections.Generic;
using System.Linq.Expressions;
using System.Threading.Tasks;
using Cylong.MongoDB.Extension;
namespace Cylong.MongoDB
{
    public interface IBaseMongo<TEntity> where TEntity : class, IEntity
    {
        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        Task AddAsync(TEntity entity);

        /// <summary>
        /// 新增
        /// </summary>
        /// <param name="entity"></param>
        void Add(TEntity entity);

        /// <summary>
        /// 删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        Task DeleteById(long id);

        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        Task Update(TEntity model);

        /// <summary>
        /// 更新指定字段
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        Task<long> Update<T>(Expression<Func<T, bool>> predicate, Expression<Func<T, T>> lambda) where T : class;

        /// <summary>
        /// 单个实体
        /// </summary>
        /// <param name="predicate">条件</param>
        /// <param name="projector">查询字段</param>
        /// <returns></returns>
        Task<TEntity> GetAsync(Expression<Func<TEntity, bool>> predicate, Expression<Func<TEntity, object>> projector = null);

        /// <summary>
        /// 
        /// </summary>
        /// <typeparam name="TDto"></typeparam>
        /// <param name="predicate"></param>
        /// <param name="projector"></param>
        /// <returns></returns>
        Task<List<TDto>> GetDtoAsync<T, TDto>(Expression<Func<T, bool>> predicate, Expression<Func<T, TDto>> projector) where T : class where TDto : class, new();
        /// <summary>
        /// 多个实体
        /// </summary>
        /// <param name="predicate">条件</param>
        /// <param name="projector">查询字段</param>
        /// <returns></returns>
        Task<List<TEntity>> GetListAsync(Expression<Func<TEntity, bool>> predicate, Expression<Func<TEntity, TEntity>> projector = null);
        ///// <summary>
        ///// 通用过滤条件
        ///// </summary>
        ///// <param name="IsDelete"></param>
        ///// <returns></returns>
        //Expression<Func<TEntity, bool>> Where(bool IsDelete = false);

        ///// <summary>
        ///// 分页
        ///// </summary>
        ///// <param name="predicate">过滤条件</param>
        ///// <param name="page">分页参数</param>
        ///// <param name="projector">查询字段</param>
        ///// <param name="orderby">排序</param>
        ///// <param name="desc">是否降序</param>
        ///// <returns></returns>
        //Task<PagedResult<TDto>> GetPageListAsync<TDto>(Expression<Func<TEntity, bool>> predicate,
        //        PagedInput page,
        //        Expression<Func<TEntity, TEntity>> projector = null,
        //        Expression<Func<TEntity, object>> orderby = null,
        //        bool desc = false) where TDto : class, new();

    }
}
